﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Utils;
using System.Drawing;
using Silvermoon.OpenGL.Native;

namespace Silvermoon.Shapes
{
    /// <summary>
    /// Shape that looks like a slot machine used for <see cref="Picker"/> control.
    /// </summary>
    public class PickerShape : GradientStopShape
    {
        private Color color = Color.White;

        public PickerShape()
            : base()
        {
            End = 20;
            const byte a = 90;
            const byte b = 24;
            this.GradientStops = new GradientStop[]
            {
                new GradientStop(0, 255,b,b,b),
                new GradientStop(1, 255,a,a,a),
                new GradientStop(6, 255,255,255,255),
                new GradientStop(14, 255,255,255,255),
                new GradientStop(19,255,a,a,a),
                new GradientStop(20, 255,b,b,b)
            };
        }

        public PickerShape(Color color)
            : this()
        {
            this.Color = color;
        }

        public override Color Color
        {
            get { return color; }
            set
            {
                if (color != value)
                {
                    color = value;
                    InvalidateColor();
                }
            }
        }

        private void InvalidateColor()
        {
            GlColor centerColor = ColorUtil.AlphaBlendColor(color, Color.Black, 128);
            GlColor borderColor = this.color;
            GradientStop[] stops = GradientStops;
            stops[0].Color = borderColor;
            stops[1].Color = centerColor;
            stops[2].Color = centerColor;
            stops[0].Color = borderColor;

            Invalidate();
        }

        protected override Shape CreateClone()
        {
            return new PickerShape();
        }
    }
}
